package com.jinyu.jyly.ui.community;

import android.app.Activity;


import com.jinyu.jyly.base.BasePresenter;
import com.jinyu.jyly.bean.AllInfoBean;
import com.jinyu.jyly.net.DataManager;

import rx.Subscription;
import rx.functions.Action1;

public class CommunityPresenter extends BasePresenter<CommunityContract.View> implements CommunityContract.Presenter {

    public CommunityPresenter(Activity activity, CommunityContract.View view) {
        super(activity, view);

    }

    /**
     * 获取直推用户
     */
    @Override
    public void getChildsList() {
        Subscription subscribe = DataManager.getInstance().getChildsList()
                .subscribe(new Action1<AllInfoBean>() {
                    @Override
                    public void call(AllInfoBean InfoData) {
                        if (InfoData != null) {
                            mView.onChildsList(InfoData);
                        }
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        handleError(throwable);
                        throwable.printStackTrace();
                        mView.onFailer(throwable);
                    }
                });
        addSubscribe(subscribe);
    }

    /**
     * 获取用户信息
     */
    @Override
    public void getUserView() {
        Subscription subscribe = DataManager.getInstance().getUserView()
                .subscribe(new Action1<AllInfoBean>() {
                    @Override
                    public void call(AllInfoBean info) {
                        if (info != null) {
                            mView.onGetUserView(info);
                        }
                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        handleError(throwable);
                        throwable.printStackTrace();
                        mView.onFailer(throwable);

                    }
                });
        addSubscribe(subscribe);
    }



}
